package com.github.ghsea.sso.client.security.shiro;

import com.github.ghsea.sso.client.common.SsoJedisPool;
import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 定义AuthenticatingRealm和AuthorizingRealm使用的CacheManager
 *
 * @author guhai
 */

@Component(value = "cacheManager")
public class JedisCacheManager implements CacheManager {

    private String cacheKeyPrefix = "sso_shiro_cache_";

    @Autowired
    private SsoJedisPool jedisPool;

    @Override
    public <K, V> Cache<K, V> getCache(String name) throws CacheException {
        return new JedisCache(cacheKeyPrefix + name, jedisPool);
    }

}
